package com.chatgpt.platformbasedchatgpt.service.impl;

import cn.hutool.crypto.digest.MD5;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chatgpt.platformbasedchatgpt.dao.User;
import com.chatgpt.platformbasedchatgpt.mapper.UserMapper;
import com.chatgpt.platformbasedchatgpt.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Chat
 * @since 2023-12-03
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    public User getUser(User user){
        return userMapper.selectOne(new LambdaQueryWrapper<User>()
                .eq(User::getAccount,user.getAccount())
                .eq(User::getPassword,user.getPassword())
        );
    }

    @Override
    public int insertUser(User user) {
        User one = userMapper.selectOne(new LambdaQueryWrapper<User>()
                .eq(User::getAccount, user.getAccount()));
        if(one==null){
            if(user.getName().isEmpty()){
                user.setName("张三");
            }
            return userMapper.insert(user);
        }else {
            return 2;
        }

    }



    public int updateUser(User user){
        return  userMapper.updateById(user);
    }

}
